package com.gopi.utilities.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.TimerTask;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;

import com.gopi.remfilebrowser.gui.GUIUtil;
import com.gopi.remfilebrowser.util.FileBrowserConstants;

public class CustomTreeCellRenderer implements TreeCellRenderer 
{
	private JPanel panel;
	private JLabel label;
	private TreeCellRenderer defaultRenderer;
	
	public CustomTreeCellRenderer()
	{
		super();
		panel = GUIUtil.createGridBagPanel();
		label = new JLabel();
		label.setHorizontalAlignment(JLabel.LEFT);
		GridBagConstraints gc = new GridBagConstraints();
		GUIUtil.fillComponent(panel,label);
		defaultRenderer = new DefaultTreeCellRenderer();
	}
	
	public Component getTreeCellRendererComponent(JTree tree, Object value,
			  boolean sel,
			  boolean expanded,
			  boolean leaf, int row,
			  boolean hasFocus)
	{
		if(value instanceof NewAbstractTreeNode)
		{
			NewAbstractTreeNode node = (NewAbstractTreeNode) value;
			label.setText(value.toString());
			label.setIcon(ImageLoader.getInstance().getIcon(node.getIconKey()));
			if(hasFocus && sel)
			{
				panel.setBackground(FileBrowserConstants.TREE_NODE_SELECTED_COLOR);
			}
			else if(sel)
			{
				panel.setBackground(FileBrowserConstants.TREE_NODE_UNSELECTED_COLOR);
			}
			else
			{
				panel.setBackground(Color.white);
			}
			return panel;
		}
		return defaultRenderer.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);
	}
}
